$(document).ready(function(){
	var url="../UserInfoServlet?method=GetUserInfo";
	getUserInfo(url,"myself");
	getOperationLog(url,"myself");
	getPaymentsInfo(url,"myself");
	getUserWebsite("../UserWebsiteServlet?method=getWebsite","myself");
	getUserKeyword("../UserKeywordServlet?method=getKeywords","myself");
//	修改用户信息编辑按钮事件
	$("#edit").click(function(){
		$(".well-sm").hide();
		editUserInfo(url);
	});
//	用户信息提交按钮事件
	$("#submitsplcial").click(function(){
//		此处的url应对应处理 修改用户信息的servlet
		$.ajax({
			"type":"get",
			"url":url,
			"data":{
				"user_id":"myself"
			},
			success:function(data){
				location.reload();
			},
			error:function(){
				console.log("error");
			}
		})
		
		$("#edit").attr("display","block");
		$("#submitsplcial").attr("display","none");
	});
//	修改密码提交按钮
	$("#changPasswordBtn").click(function(){
//		url应对应修改用户密码的servlet
		var oldpaswd = $("#oldpassword").val();
		var newpassword1 = $("#newpassword1").val();
		var newpassword2 = $("#newpassword2").val();
		if(newpassword1==newpassword2){
			$.ajax({
				"type":"get",
				"url":"../UserInfoServlet?method=ChangeUserPassword",
				"data":{
					"oldpaswd":oldpaswd,
					"newpassword":newpassword1
				},
				success:function(data){
					//location.reload();
				},
				error:function(){
					console.log("error");
				}
			})
		}
		else{
			alert("密码不一致")
		}
		console.log("oldpaswd:"+oldpaswd);
		
	});
//	添加关注网页按钮事件
	$("#addwebpage_btn").click(function(){
		$.blockUI({
			message:$('#addwebpage_div'),
			css: {
				padding:"20px",
                border: "1px",                   // 无边界
                width:"1000px",                     // 中间框框的宽度
                top:"20%",                        // 高居中
                left:"20%"                        // 左居中
           },
        
				
		});
	});
//	关注网页增加框内 取消按钮事件
	$("#webpage_cancel").click(function(){
		 $.unblockUI();
	});
//	关注网页增加框内 确认按钮事件
	$("#webpage_confirm").click(function(){
		var userweb = $("#userweb_ipt").val();
		$.ajax({
			"type":"post",
			"url":"../UserWebsiteServlet?method=addWebsite",
			"data":{
				"website":userweb,
			},
			success:function(data){
				console.log(data);
				location.reload();
			},
			error:function(){
				console.log("error");
			}
			});
	});
//	添加关注关键词按钮事件
	$("#addkeyword_btn").click(function(){
		$.blockUI({
			message:$('#addkeyword_div'),
			css: {
				padding:"20px",
                border: "1px",                   // 无边界
                width:"1000px",                     // 中间框框的宽度
                top:"20%",                        // 高居中
                left:"20%"                        // 左居中
           },
        
				
		});
	});
//	关注关键词增加框内 取消按钮事件
	$("#addkeyword_cancel").click(function(){
		 $.unblockUI();
	});
//	关注关键词增加框内 确认按钮事件
	$("#addkeyword_confirm").click(function(){
		var keyword = $("#userkeyword_ipt").val();
		$.ajax({
			"type":"post",
			"url":"../UserKeywordServlet?method=addKeyword",
			"data":{
				"keyword":keyword,
			},
			success:function(data){
				console.log(data);
				location.reload();
			},
			error:function(){
				console.log("error");
			}
			});
	});
})

function editUserInfo(url){
//	<input name="username" type="text"  required="required" value="" onBlur="chkUserName(this)" id="username">
	
	$.ajax({
		"type":"get",
		"url":url,
		"data":{
			"user_id":"myself"
		},
		success:function(data){
			console.log("修改用户信息="+data);
			var userinfo = JSON.parse(data).userinfo;
			var username = "<input class='editbox lifont' name='username' type='text'   required='' value='"+userinfo.username+"'>"
			$(username).appendTo("#username");
			var sex= "<input class='editbox lifont' name='sex' type='text' readonly=''  required='' value='"+userinfo.sex+"'>"
			$(sex).appendTo("#sex");
			var email= "<input class='editbox lifont' name='email' type='text'  required='' value='"+userinfo.email+"'>"
			$(email).appendTo("#email");
			var phonenumb= "<input class='editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.phonenumb+"'>"
			$(phonenumb).appendTo("#phonenumb");
			var birth= "<input class=' editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.birth+"'>"
			$(birth).appendTo("#birth");
			var idcardnumb= "<input class='editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.idcardnumb+"'>"
			$(idcardnumb).appendTo("#idcardnumb");
			var payment= "<input class='editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.payment+"'>"
			$(payment).appendTo("#payment");
			var subscribeway= "<input class='editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.subscribeway+"'>"
			$(subscribeway).appendTo("#subscribeway");
			var usercode= "<input class='editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.usercode+"'>"
			$(usercode).appendTo("#usercode");
			var roleDetail= "<input class='editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.roleDetail+"'>"
			$(roleDetail).appendTo("#roleDetail");
			var rigisterdate= "<input class='editbox lifont' name='phonenumb' type='text'  required='' value='"+userinfo.rigisterdate+"'>"
			$(rigisterdate).appendTo("#rigisterdate");
			
			
		},
		error:function(){
			console.log("error");
		}
	})
//	$("#submitsplcial").attr("disabled",false);
//	$("#edit").attr("disabled",true);
	$("#edit").css("display","none");
	$("#submitsplcial").css("display","block");
}
